package com.flickr.presenters;

import android.os.AsyncTask;
import com.flickr.api.FlickrService;
import com.flickr.api.FlickrServiceException;
import com.flickr.api.auth.AuthenticationService;
import com.flickr.api.auth.Caller;
import com.flickr.api.photosets.PhotosetsService;
import com.flickr.views.PhotosetsView;


public class PhotosetsPresenter extends Presenter<PhotosetsView>
{
    
    private PhotosetsService photosetsService;

    public PhotosetsPresenter(PhotosetsView view,
                              PhotosetsService photosetsService) {
        super(view);
        this.photosetsService = photosetsService;
    }

    
    public void loadPhotosets(final Caller caller) {
        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params)
            {
                try {
                    view.setPhotosets(photosetsService.getPhotosets(caller, FlickrService.MAX_PER_PAGE, 0).asList());
                    return null;
                } catch (FlickrServiceException ex) {
                    throw new UnsupportedOperationException(ex.getMessage(), ex);
                }
            }
            
        };
        task.execute();
    }
    
}
